package javase.homework.first;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;

public class SchoolClass {
	private int scid;
	private HashSet<Student> students=new HashSet<Student>();
	
	public SchoolClass(HashSet<Student> students) {
		this.students = students;
	}
	public SchoolClass(int scid, HashSet<Student> students) {
		this.scid = scid;
		this.students = students;
	}
	public SchoolClass() {
	}
	public int getScid() {
		return scid;
	}
	public void setScid(int scid) {
		this.scid = scid;
	}
	public HashSet<Student> getStudents() {
		return students;
	}
	public void setStudents(HashSet<Student> students) {
		this.students = students;
	}
	
	public void addStudent(Student s){
		students.add(s);
	} 
	public void removeCourse(String name){
		Iterator<Student> it=students.iterator();
		while(it.hasNext()){
			Student s=it.next();
			if(s.getName().equals(name)){
				students.remove(s);
			}
		}
	}
	public Map<Course,Integer> account(){
		Map<Course, Integer> map=new HashMap<Course, Integer>();
		Iterator<Student> sit=students.iterator();
		while(sit.hasNext()){
			Student s=sit.next();
			HashSet<Course> courses=s.getCourses();
			Iterator<Course> cid=courses.iterator();
			while(cid.hasNext()){
				Course c=cid.next();
				if(map.containsKey(c)){
					map.put(c, map.get(c)+1);
				}else{
					map.put(c, 1);
				}
			}
			
		}
		return map;
	}
	
}
